/****************************************************************
Copyright 1990 - 1997 by AT&T, Lucent Technologies and Bellcore.

Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T, Bell Laboratories,
Lucent or Bellcore or any of their entities not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

AT&T, Lucent and Bellcore disclaim all warranties with regard to
this software, including all implied warranties of
merchantability and fitness.  In no event shall AT&T, Lucent or
Bellcore be liable for any special, indirect or consequential
damages or any damages whatsoever resulting from loss of use,
data or profits, whether in an action of contract, negligence or
other tortious action, arising out of or in connection with the
use or performance of this software.
****************************************************************/



#ifndef FIO_INCLUDE
#define FIO_INCLUDE

#ifndef SYSDEP_H_INCLUDED
#include "sysdep1.h"
#endif
#include "stdio.h"
#include <errno.h>
#ifndef NULL
/* ANSI C */
#include "stddef.h"
#endif

#include "f2c.h"

#ifndef SEEK_SET
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#endif

#ifndef FOPEN
#define FOPEN fopen
#endif

#ifndef FREOPEN
#define FREOPEN freopen
#endif

#ifndef FSEEK
#define FSEEK fseek
#endif

#ifndef FSTAT
#define FSTAT fstat
#endif

#ifndef FTELL
#define FTELL ftell
#endif

#ifndef OFF_T
#define OFF_T long
#endif

#ifndef STAT_ST
#define STAT_ST stat
#endif

#ifndef STAT
#define STAT stat
#endif

#ifdef MSDOS
#ifndef NON_UNIX_STDIO
#define NON_UNIX_STDIO
#endif
#endif

#ifdef UIOLEN_int
typedef int uiolen;
#else
typedef long uiolen;
#endif

/*units*/
typedef struct
{
	FILE *ufd;	/*0=unconnected*/
	char *ufnm;
#ifndef MSDOS
	long uinode;
	int udev;
#endif
	int url;	/*0=sequential*/
	flag useek;	/*true=can backspace, use dir, ...*/
	flag ufmt;
	flag urw;	/* (1 for can read) | (2 for can write) */
	flag ublnk;
	flag uend;
	flag uwrt;	/*last io was write*/
	flag uscrtch;
} unit;

#undef Void
#ifdef KR_headers
#define Void /*void*/
extern int (*f__getn)();	/* for formatted input */
extern void (*f__putn)();	/* for formatted output */
extern void x_putc();
extern long f__inode();
extern VOID sig_die();
extern int (*f__donewrec)(), t_putc(), x_wSL();
extern int c_sfe(), err__fl(), xrd_SL(), f__putbuf();
#else
#define Void void
#ifdef __cplusplus
extern "C" {
#endif
	 int(*f__getn)(void);	/* for formatted input */
	 void(*f__putn)(int);	/* for formatted output */
	 void x_putc(int c);
	 long f__inode(char*, int*);
	 void sig_die(const char*, int);
	 void f__fatal(int, const char*);
	 int t_runc(alist*);
	 int f__nowreading(unit*), f__nowwriting(unit*);
	 int fk_open(int, int, ftnint);
	 int en_fio(void);
	 void f_init(void);
	 int(*f__donewrec)(void), t_putc(int), x_wSL(void);
	 void b_char(const char*, char*, ftnlen), g_char(const char*, ftnlen, char*);
	 int c_sfe(cilist*), z_rnew(void);
	 int err__fl(int, int, const char*);
	 int xrd_SL(void);
	 int f__putbuf(int c);
#endif
	 flag f__init;
	 cilist *f__elist;	/*active external io list*/
	 flag f__reading, f__external, f__sequential, f__formatted;
	 int(*f__doend)(Void);
	 FILE *f__cf;	/*current file*/
	 unit *f__curunit;	/*current unit*/
	 unit f__units[];
#define err(f,m,s) {if(f) errno= m; else f__fatal(m,s); return(m);}
#define errfl(f,m,s) return err__fl((int)f,m,s)

	/*Table sizes*/
#define MXUNIT 100

	 int f__recpos;	/*position in current record*/
	 OFF_T f__cursor;	/* offset to move to */
	 OFF_T f__hiwater;	/* so TL doesn't confuse us */
#ifdef __cplusplus
}
#endif

#define WRITE	1
#define READ	2
#define SEQ	3
#define DIR	4
#define FMT	5
#define UNF	6
#define EXT	7
#define INT	8

#define buf_end(x) (x->_flag & _IONBF ? x->_ptr : x->_base + BUFSIZ)

#endif	// FIO_INCLUDE